package com.hd.pzhwlxt.controller.model4;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hd.pzhwlxt.pojo.GoodsOrder;
import com.hd.pzhwlxt.pojo.Trans;
import com.hd.pzhwlxt.service.GoodsOrderService;
import com.hd.pzhwlxt.service.MaterialOrderService;
import com.hd.pzhwlxt.service.TransService;
import com.hd.pzhwlxt.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @create: 2022-09-26 16:41
 * @author: 怀念天空
 * @Description:
 */
@RestController
public class TransController {

    @Autowired
    private GoodsOrderService goodsOrderService;

    @Autowired
    private MaterialOrderService materialOrderService;

    @Autowired
    private TransService transService;


    /**
     * 返回未处理的订单，已处理的不显示
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/orderToDo")
    public Response<Object> getOrderToDo(@RequestParam(value = "pageNum", required = false) Integer pageNum, @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        if (pageNum == null || pageSize == null) {
            List<GoodsOrder> result = goodsOrderService.getGoodsOrderToDo();
            if (result != null) {
                return Response.createSuccessResponse("查询成功", result);
            }
        } else {
            Page<GoodsOrder> result = goodsOrderService.getGoodsOrderToDoPage(new Page<>(pageNum, pageSize));
            if (result != null) {
                return Response.createSuccessResponse("查询成功", result);
            }
        }
        return Response.createErrorResponse("查询失败");
    }

    /**
     * 返回已处理的订单
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/orderOnDo")
    public Response<Object> getOrderOnDo(@RequestParam(value = "pageNum", required = false) Integer pageNum, @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        if (pageNum == null || pageSize == null) {
            List<GoodsOrder> result = goodsOrderService.getGoodsOrderOnDo();
            if (result != null) {
                return Response.createSuccessResponse("查询成功", result);
            }
        } else {
            Page<GoodsOrder> result = goodsOrderService.getGoodsOrderOnDoPage(new Page<>(pageNum, pageSize));
            if (result != null) {
                return Response.createSuccessResponse("查询成功", result);
            }
        }
        return Response.createErrorResponse("查询失败");
    }


    @PutMapping("/orderToDo")
    public Response<String> updateTransInfo(@RequestBody Trans trans){
        boolean update = transService.updateTransInfo(trans);
        if (update){
            return Response.createSuccessResponse("修改成功");
        }
        return Response.createErrorResponse("修改失败");
    }

    @DeleteMapping("/orderToDo/{ids}")
    public Response<String> deleteTransInfo(@PathVariable Integer[] ids){
        boolean remove = transService.removeByIds(Arrays.asList(ids));
        if (remove) {
            return Response.createSuccessResponse("删除成功");
        }
        return Response.createErrorResponse("删除失败");
    }
}
